ApiHost += "/{subFolder}";

$(function(){
    initPage();
    loadData();
});

//初始化页面元素
function initPage() {

}

//加载数据
function loadData() {
    var id=GetQueryString("id");
    var url = ApiHost + "/{tblName}GetById";
    $.ajax({
            type: "post",
            url: url,
            data: {
                id:id
            },
            dataType: "json",
            error: function (request) {
                ajaxError(request, $(this));
            },
            success: function (result) {
                ajaxSuccess(result, $(this));
                var code=result.statecode;
                if(code==0){
                    loadJson(result.data);
                }else{
                    layerAlert("获取失败："+result.message);
                }
            }
        }
    );

}

//保存数据
function formAddSubmit() {
    var url = ApiHost + "/{tblName}Add";
    var formData =$('#formadd').serialize();
    $.ajax({
            type: "post",
            url: url,
            data: formData,
            dataType: "json",
            error: function (request) {
                ajaxError(request, $(this));
            },
            success: function (result) {
                ajaxSuccess(result, $(this));
                var code=result.statecode;
                if(code==0){
                    //layerAlert("提交成功");
                    layerAlert("成功",function () {
                        parent.layerCallBack();
                        closeLayer();
                    })
                }else{
                    layerAlert("提交失败："+result.message);
                }
            }
        }
    );

}

